# -*- coding: utf-8 -*-
"""
@File:    send_service.py
@Author:  jk.dong
@Desc:    None
"""
from docwork import logging, datetime
from docwork.dao.send_dao import sent
from docwork.config import RUN_CONF


def send_service_work():
    logging.info("启动发送服务...")
    # 添加发送服务暂停时间段
    send_suspend = False
    suspend_time = RUN_CONF['run-setting'].get('send_suspend_time')
    if suspend_time:
        # 将时分秒转换成当天的时间，并根据当前时间判断是否在这个时间段内
        now = datetime.datetime.now().strftime('%H:%M:%S')
        dsp_now = datetime.datetime.strptime(now, '%H:%M:%S')
        send_suspend_start = datetime.datetime.strptime(suspend_time.split('-')[0], '%H:%M:%S')
        send_suspend_stop = datetime.datetime.strptime(suspend_time.split('-')[1], '%H:%M:%S')
        if (dsp_now >= send_suspend_start) and (dsp_now <= send_suspend_stop):
            send_suspend = True
    if send_suspend:
        logging.info(
            f"进入了每日暂停发送报告的时间范围，暂停发送: {suspend_time.split('-')[0]}-{suspend_time.split('-')[1]}")
    else:
        logging.info("************ START: Send ************")
        sent()
        logging.info("************ END: Send ************")
